#!/usr/bin/Python
#! -*- coding：utf-8 -*-
#自动取款机

#查找Cid函数
def Serch_Cid(a):
	for i in range(len(Cardlist)):
		if a == Cardlist[i]['cid']:
			print('卡号输入正确!')
			return 1
			
#查找Pwd函数
def Serch_Pwd(b):
	for i in range(len(Cardlist)):
		if b == Cardlist[i]['cid']:
			c = Cardlist[i]['pwd']
			return c
			
#查找cash函数
def Serch_Cash(c):
	for i in range(len(Cardlist)):
		if c == Cardlist[i]['cid']:
			d = Cardlist[i]['cash']
			return d

#取出cash函数
def Fix_Cash(d):
	for i in range(len(Cardlist)):
		if d == Cardlist[i]['cid']:
			Cardlist[i]['cash'] = Cardlist[i]['cash'] - Out
			
#存入cash函数
def In_Cash(e):
	for i in range(len(Cardlist)):
		if e == Cardlist[i]['cid']:
			Cardlist[i]['cash'] = Cardlist[i]['cash'] + In

#预制银行卡信息,便于测试
Cardlist = [
	{'cid':111111,'pwd':111111,'cash':0},
	{'cid':222222,'pwd':222222,'cash':300},
	{'cid':333333,'pwd':333333,'cash':6000}]

#输出预制银行卡信息,便于测试
print('='*20,'已有的银行卡账号','='*20)
for i in range(len(Cardlist)):
	print('银行卡号:{0:<10} 密码:{1:<10} 存款:{2:<10}'.format(Cardlist[i]['cid'],Cardlist[i]['pwd'],Cardlist[i]['cash']))
print('='*60)

#取款机登录界面
print('='*20,'py取款机登录','='*20)
print('请先登录取款机!')
while True:
	Cid = int(input('请输入卡号:'))
	m = Serch_Cid(Cid)
	if m == 1:
		break
	else:
		print('输入有误,请重新输入!')
while True:
	Pwd = int(input('请输入密码:'))
	n = Serch_Pwd(Cid)
	if n == Pwd:
		print('密码输入正确!')
		print('恭喜,登陆成功!')
		break
	else:
		print('密码输入有误,请重新输入!')

#取款机界面
while True:
	print('='*20,'py取款机','='*20)
	print('1.{0:<20} 2.{1:<20}'.format('余额','取钱'))
	print('3.{0:<20} 4.{1:<20}'.format('存钱','登出'))
	print('='*45)
	Ch = input('请选择要使用的功能:')
	if Ch == '1':
		print('='*20,'银行卡余额','='*20)
		Cash = Serch_Cash(Cid)
		print('您当前的银行卡余额为:',Cash)
		print('='*60)
	elif Ch == '2':
		print('='*20,'银行卡取钱','='*20)
		Out = int(input('请输入你要取出的金额:'))
		Cash = Serch_Cash(Cid)
		if Out > Cash:
			print('您当前余额不足!')
		else:
			print('取款成功!')
			Fix_Cash(Cid)
			print('='*60)
	elif Ch == '3':
		print('='*20,'银行卡存钱','='*20)
		In = int(input('请输入你要存入的金额:'))
		print('存款成功!')
		In_Cash(Cid)
		print('='*60)
	elif Ch == '4':
		print('='*20,'再见','='*20)
		break
	else:
		print('输入的序号错误,请重新输入!')